package org.hoyi.servmotions;

import java.io.File;

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.hoyi.DB.ctrl.Console;
import org.hoyi.util.DateTimeUtil;

/**
 * 监听HTML,css,js 等静态资源被修改，并反馈给前端以便了解是否需要刷新页面.
 * @author Administrator
 *
 */
public class refreshpageListener extends FileAlterationListenerAdaptor {
	
	public void Restart(String absopath) {
		absopath = absopath.toLowerCase();
		if (absopath.endsWith(".html") || absopath.endsWith(".js")
				|| absopath.endsWith(".css")|| absopath.endsWith(".txt")
				) {
			refreshpage_motion.lastModiTime = DateTimeUtil.getCurrentDateTime();
		}
	}

	@Override
	public void onFileChange(File file) {
		Console.Info("onFileChange:" + file.getAbsolutePath() + ",LastRefreshTime:" + refreshpage_motion.lastModiTime);
		Restart(file.getAbsolutePath());
	}
	
	@Override
	public void onFileCreate(File file) {
		Console.Info("onFileCreate:" + file.getAbsolutePath() + ",LastRefreshTime:" + refreshpage_motion.lastModiTime);
		Restart(file.getAbsolutePath());
	}
	
	@Override
	public void onFileDelete(File file) {
		Console.Info("onFileDelete:" + file.getAbsolutePath() + ",LastRefreshTime:" + refreshpage_motion.lastModiTime);
		Restart(file.getAbsolutePath());
	}
}
